package com.loong.common.rest.rpc;

import com.loong.common.enumerate.RPCResponseCode;
import com.loong.common.enumerate.ResultCode;
import com.loong.common.rest.Result;
import lombok.*;

import java.io.Serializable;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RPCResponse<T> implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 2054492155488251365L;

	/**
	 * 响应的消息内容
	 */
	private String message;

	/**
	 * 响应的状态码
	 */
	private Integer code;

	private Boolean success;

	/**
	 * 响应的数据内容
	 */
	private T data;
	public static <R> RPCResponse success(R data){
		return RPCResponse.<R>builder()
				.data(data)
				.code(RPCResponseCode.SUCCESS.getCode())
				.message(RPCResponseCode.SUCCESS.getMessage())
				.success(true)
				.build();
	}
	public static <R> RPCResponse.RPCResponseBuilder success(){
		return RPCResponse.<R>builder()
				.code(RPCResponseCode.SUCCESS.getCode())
				.message(RPCResponseCode.SUCCESS.getMessage())
				.success(true);
	}
	public static <R> RPCResponse.RPCResponseBuilder fail(){
		return RPCResponse.<R>builder()
				.code(RPCResponseCode.FAIL_DEFAULT.getCode())
				.message(RPCResponseCode.FAIL_DEFAULT.getMessage())
				.success(false);
	}
	public  static <R> RPCResponse fail(R data){
		return RPCResponse.<R>builder()
				.data(data)
				.code(RPCResponseCode.FAIL_DEFAULT.getCode())
				.message(RPCResponseCode.FAIL_DEFAULT.getMessage())
				.success(false)
				.build();
	}
	public  static <R> RPCResponse fail(String message){
		return RPCResponse.<R>builder()
				.code(RPCResponseCode.FAIL_DEFAULT.getCode())
				.message(message)
				.success(false)
				.build();
	}
}
